package com.example.utils;


import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.Map;

/**
 * 令牌
 */
public class JwtUtils {

    private static final String singKey ="jiaozhanna" ;
    private static final Integer time =3600 * 1000 ;

    public static String generateJwt(Map<String,Object> claims){
        String jwt = Jwts.builder()
                .signWith(SignatureAlgorithm.HS256, singKey)// 签名算法
                .setClaims(claims)//自定义数据
                .setExpiration(new Date(System.currentTimeMillis()+time))//令牌有效期
                .compact();

        return jwt;
    }



    public static Claims parseJWT(String jwt){
        Claims claims = Jwts.parser()
                .setSigningKey(singKey)
                .parseClaimsJws(jwt)
                .getBody();
        return claims;

    }

}
